<template>
<div v-show="isShow" class="modal-container">
  <div
      :style="{
        width: `${width}px`,
        height: `${height}px`,
        marginTop: `calc(((100vh - ${height}) / 2) - ${height / 5}px)`
      }"
      class="modal-box">
    <div class="modal-header">
      <div>{{ title }}</div>
      <div @click="closed"><CloseOutlined/></div>
    </div>
    <div class="modal-center">
      <slot></slot>
    </div>
  </div>
</div>
</template>

<script lang="ts">
import {defineComponent} from "vue";
import { CloseOutlined } from "@ant-design/icons-vue";

export default defineComponent({
  props: {
    title: {
      type: String,
      default: "标题"
    },
    isShow: {
      type: Boolean,
      default: false
    },
    width: {
      type: Number,
      default: 400
    },
    height: {
      type: Number,
      default: 380
    }
  },
  setup(props, context){
    const closed = ()=>{
      context.emit("closed")
    }
    return {
      closed
    }
  },
  components: {
    CloseOutlined
  }
})
</script>

<style lang="scss" scoped>
.modal-container {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1000;
  overflow: auto;
  outline: 0;
  background-color: rgba(0, 0, 0, 0.45);
  .modal-box {
    position: relative;
    display: flex;
    flex-direction: column;
    margin: 0 auto;
    margin-top: calc(((100vh - 500px) / 2) - 40px);
    background: #fff;
    border-radius: 2px;
    border: 1px solid #ebedf0;
    >div{
      padding-left: 24px;
      padding-right: 24px;
      box-sizing: border-box;
    }
    .modal-header {
      display: flex;
      justify-content: space-between;
      width: 100%;
      height: 52px;
      padding-top: 14px;
      padding-bottom: 14px;
      font-size: 18px;
      line-height: 24px;
      border-bottom: 1px solid #EEE;
      > div:first-of-type {
        font-size: 18px;
        color: #333;
        font-weight: bold;
      }
      > div{
        color: rgba(0, 0, 0, 0.45);
      }
    }
    .modal-center {
      flex: 1;
    }
  }
}
</style>
